<?php
set_time_limit(0);
include_once("config.php");
include_once("model/article.php");
include_once("model/function.php");

function make_cat_html($id){
	global $prefix,$website;
	
	$ids=preg_replace("/^0,/",'',get_all_sub_catalog($id));
	$ids=explode(',',$ids);
	foreach($ids as $v){
		$all_ids=preg_replace("/^0,/",'',get_all_sub_catalog($v));
		$result=mysql_query("select id from ".$prefix."article where catalog in(".$all_ids.")");
		$page=1;
		$i=1;
		do{
			if($i % 25 ==1){
				$str=file_get($website."/artlist.php?id=".$v."&page=".$page);
				$page++;
			}
			$i++;
		}while($res=mysql_fetch_array($result));
	}
}


function make_art_html($id){
	global $prefix,$website;
	
	$ids=preg_replace("/^0,/",'',get_all_sub_catalog($id));
	$res=mysql_query("select id from ".$prefix."article where catalog in(".$ids.")");
	while($a=mysql_fetch_array($res)){
		$str=file_get($website."/showarticle.php?id=".$a['id']);
	}
}

if($_GET['type']=='cat'){
	if(isset($_GET['catalog_id'])&&$_GET['catalog_id']!=''){
		make_cat_html($_GET['catalog_id']);
		echo "生成栏目html完成";
	}
}elseif($_GET['type']=='art'){
	if(isset($_GET['catalog_id'])&&$_GET['catalog_id']!=''){
		make_art_html($_GET['catalog_id']);
		echo "生成文章html完成";
	}
}
mysql_close($conn);
?>